package com.wms.controller;

import com.wms.bean.PageBean;
import com.wms.bean.ResultBean;
import com.wms.core.R;
import com.wms.dto.SuserUpVo;
import com.wms.entity.Suser;
import com.wms.service.SuserService;
import com.wms.dto.SuserVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/suser")
@Api(tags = "库管员管理--张开心")
@Slf4j
public class SuserController {

    @Autowired
    private SuserService suserService;
    @PostMapping ("/queryPageAndCondition")
    @ApiOperation(value = "分页查询库管员列表和条件查询")
    public ResultBean<PageBean<List<Suser>>> queryPage(@ApiParam(value = "库管员查询条件") @RequestBody SuserVo suserVo) {
        log.info("分页查询库管员列表: 页码={}, 每页条数={}, 条件={}", suserVo);
        PageBean<List<Suser>> pageBean = suserService.queryPageAndContion(suserVo);
        return R.success("分页查询成功", pageBean);
    }

    @PostMapping("/insert")
    @ApiOperation(value = "新增库管员")
    public ResultBean<Integer> insert(
            @ApiParam(value = "库管员信息", required = true) @RequestBody SuserUpVo suserUpVo) {
        log.info("新增库管员: {}", suserUpVo);
        int rows = suserService.insert(suserUpVo);
        return rows==1?R.success("新增成功", rows):R.fail("新增失败");
    }

    @PutMapping("/update")
    @ApiOperation(value = "更新库管员信息")
    public ResultBean<Integer> update(
            @ApiParam(value = "库管员信息", required = true) @RequestBody SuserUpVo suserUpVo) {
        log.info("更新库管员: {}", suserUpVo);
        int rows = suserService.update(suserUpVo);
        return rows==1? R.success("更新成功", rows):R.fail("插入失败");
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "物理删除库管员")
    public ResultBean<Integer> deleteById(
            @ApiParam(value = "库管员ID", required = true) @PathVariable("id") int id) {
        log.info("物理删除库管员: ID={}", id);
        int rows = suserService.deleteById(id);
        return rows==1?R.success("删除成功", rows):R.fail("删除失败");
    }

    @PutMapping("/updateStatus/{id}")
    @ApiOperation(value = "逻辑删除库管员(更新状态)")
    public ResultBean<Integer> updateStatus(
            @ApiParam(value = "库管员信息(含ID和状态)", required = true) @PathVariable("id") int id) {
        log.info("逻辑删除库管员: {}", id);
        int rows = suserService.updateStatus(id);
        return rows==1?R.success("状态更新成功", rows):R.fail("删除失败");
    }

    @PutMapping("/updatePassword/{id}")
    @ApiOperation(value = "重制密码(更新状态)")
    public ResultBean<Integer> updatePassword(
            @ApiParam(value = "库管员信息(含ID和状态)", required = true) @PathVariable("id") int id
    ) {
        log.info("逻辑删除库管员: {}");
        int rows = suserService.updatePassword(id);
        return rows==1?R.success("状态更新成功", rows):R.fail("重置失败");
    }




}